package design_pattern

import "log"

// go 中的工厂模式
// https://learnku.com/articles/33703
// https://zhuanlan.zhihu.com/p/81715661

// 工厂方法

type Girl interface {
	weight()
}
type FatGirl struct {
}

func (*FatGirl) weight() {
	log.Println("i am a fat girl")
}

type ThinGirl struct {
}

func (*ThinGirl) weight() {
	log.Println("i am a thin girl")
}

func CreateGirl(like string) Girl {
	if like == "fat" {
		return &FatGirl{}
	} else if like == "thin" {
		return &ThinGirl{}
	}
	return nil
}

// 抽象工厂

type AbstractFactory interface {
	CreateGirl(like string) Girl
}

type ChinaFactory struct {
}

func (*ChinaFactory) Create(like string) Girl {
	if like == "fat" {
		return &FatGirl{}
	} else if like == "thin" {
		return &ThinGirl{}
	}
	return nil
}

type AmericaFatGirl struct {
}

func (*AmericaFatGirl) weight() {
	log.Println("i am a fat american girl")
}

type AmericaThinGirl struct {
}

func (*AmericaThinGirl) weight() {
	log.Println("i am a thin american girl")
}

type AmericaFactory struct {
}

func (*AmericaFactory) Create(like string) Girl {
	if like == "fat" {
		return &AmericaFatGirl{}
	} else if like == "thin" {
		return &AmericaThinGirl{}
	}
	return nil
}
// 工厂存储

type FactoryStore struct {
	factory AbstractFactory
}

func (store *FactoryStore)createGirl(like string) Girl {
	return store.factory.CreateGirl(like)
}
